package com.sxhuayuan.parking.service.impl;

import java.math.BigDecimal;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sxhuayuan.parking.config.PayMode;
import com.sxhuayuan.parking.config.PayStatus;
import com.sxhuayuan.parking.config.Platform;
import com.sxhuayuan.parking.dao.BaseDao;
import com.sxhuayuan.parking.dao.MonthCardOrderDao;
import com.sxhuayuan.parking.entity.MemberCarPlate;
import com.sxhuayuan.parking.entity.MonthCardOrder;
import com.sxhuayuan.parking.entity.ParkingLot;
import com.sxhuayuan.parking.plugin.parking.bean.McardChargeOption;
import com.sxhuayuan.parking.service.MonthCardOrderService;
import com.sxhuayuan.parking.service.ThirdPartiesNotifyService;
import com.sxhuayuan.parking.utils.SequenceUtils;
import com.sxhuayuan.parking.utils.SettingUtils;

@Service("monthCardOrderServiceImpl")
public class MonthCardOrderServiceImpl extends BaseServiceImpl<MonthCardOrder, Long> implements MonthCardOrderService {

	@Autowired
	MonthCardOrderDao dao;
	@Autowired
	SequenceUtils sequenceUtils;

	@Override
	public BaseDao<MonthCardOrder, Long> getDAO() {
		return dao;
	}

	@Override
	public MonthCardOrder createMonthCardOrder(MemberCarPlate memberCarPlate, ParkingLot lot, BigDecimal money, String pluginId, Platform platform, PayMode payMode, String ip, String remark,
			Integer monthCount, McardChargeOption option, String currExpireDate, String preExpireDate) {
		MonthCardOrder monthCardOrder = new MonthCardOrder();
		monthCardOrder.setMoney(SettingUtils.get().setScale(money));
		monthCardOrder.setCarPlate(memberCarPlate.getCarPlate()); // 车牌号
		monthCardOrder.setPlatform(platform);// 支付类型 微信 支付宝
		monthCardOrder.setPayMode(payMode); // 支付方式 h5 原生扫码
		monthCardOrder.setPayStatus(PayStatus.notpay); // 支付状态 默认未支付
		monthCardOrder.setSn(sequenceUtils.nextIdStr()); // 自己生成的订单id
		monthCardOrder.setMonthCount(monthCount);
		monthCardOrder.setIsNoticeSuccess(false);
		monthCardOrder.setTariffID(option.getTariffId());
		monthCardOrder.setTariffName(option.getTariffName());
		monthCardOrder.setMonthlyRent(option.getCharge());
		monthCardOrder.setMember(memberCarPlate.getMember());
		monthCardOrder.setParkingLot(lot);
		monthCardOrder.setCurrExpierDate(currExpireDate);
		monthCardOrder.setPreExpireDate(preExpireDate);
		dao.save(monthCardOrder);
		return monthCardOrder;
	}

	/** 根据系统订单号查询 */
	@Override
	public MonthCardOrder findBySn(String sn) {
		return dao.findBySn(sn);
	}

	/** 根据华贝的订单号查询 */
	@Override
	public MonthCardOrder findByTradeNo(String tradeNo) {
		return dao.findByTradeNo(tradeNo);
	}

	@Override
	public void paySuccess(MonthCardOrder order, String huabeiOrderNo) {
		// TODO Auto-generated method stub
	}
}
